precision mediump float;
const float PI=3.14159265359;
float sdCircle(vec2 p, float r) {
    return length(p) - r;
}


float sdBox(vec2 p, vec2 b) {
    vec2 d = abs(p) - b;
    return length(max(d,0.))+min(max(d.x,d.y),0.);
}

mat2 rotation2d(float angle){
    float s=sin(angle);
    float c=cos(angle);

    return mat2(
        c,-s,
        s,c
    );
}

vec2 rotate(vec2 v,float angle){
    return rotation2d(angle)*v;
}


float sdEquilateralTriangle(in vec2 p,in float r)
{
    const float k=sqrt(3.);
    p.x=abs(p.x)-r;
    p.y=p.y+r/k;
    if(p.x+k*p.y>0.)p=vec2(p.x-k*p.y,-k*p.x-p.y)/2.;
    p.x-=clamp(p.x,-2.*r,0.);
    return-length(p)*sign(p.y);
}

void mainImage(out vec4 fragColor,in vec2 fragCoord){
    vec2 uv=fragCoord/iResolution.xy;

    uv = (uv - .5) * 2.;

    uv.x *= iResolution.x/iResolution.y;
    // uv.x -= 0.2;
    // uv.y -= 0.4;
    // uv *= vec2(3.,3.);
    // uv /= vec2(2.,2.);
    // uv.y *= -1.;
    // uv=rotate(uv,iTime);
    // float d = sdBox(uv, vec2(.6,.3));
    float d=sdEquilateralTriangle(uv,.5);
    float c = smoothstep(0.,0.02, d);
    fragColor = vec4(vec3(c),1.0); 
}
